package cn.source.zk.domain.dto;

import cn.source.zk.domain.entity.DBUhrja;
import cn.source.zk.domain.entity.DBUhrjb;
import cn.source.zk.domain.entity.DBUhrjc;
import lombok.Data;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author shiqi
 * @create 2025-04-27 11:19
 */
@Data
public class DBUhrjDTO {

    private LocalDateTime timedate;

    private Map<String, Object> fields = new HashMap<String, Object>();

    //构建db_ihra表
    public void buildToUhrja(DBUhrja dbUhrja, Map<Integer,String> fieldNames){
        if(dbUhrja != null){
            this.timedate = dbUhrja.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){
                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBUhrja.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("a_"+v, field.get(dbUhrja));
                    } catch (Exception e){

                    }
                });
            }
        }
    }

    public void buildToUhrjb(DBUhrjb dbUhrjb, Map<Integer,String> fieldNames){
        if(dbUhrjb != null){
            this.timedate = dbUhrjb.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){
                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBUhrjb.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("b_"+v, field.get(dbUhrjb));
                    } catch (Exception e){

                    }
                });
            }
        }
    }

    public void buildToUhrjc(DBUhrjc dbUhrjc, Map<Integer,String> fieldNames){
        if(dbUhrjc != null){
            this.timedate = dbUhrjc.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){

                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBUhrjc.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("c_"+v, field.get(dbUhrjc));
                    } catch (Exception e){

                    }
                });
            }
        }
    }

}
